package com.bkgy.controller.qualityDaily.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.controller.qualityDaily.entity.QualitydailyInfo;
import com.bkgy.controller.qualityDaily.entity.pdo.InfoReq;
import com.bkgy.controller.qualityDaily.mapper.IQualitydailyInfoMapper;
import com.bkgy.controller.qualityDaily.service.IQualitydailyInfoService;
import com.bkgy.sys.common.entity.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QualitydailyInfoServiceImpl extends ServiceImpl<IQualitydailyInfoMapper, QualitydailyInfo> implements IQualitydailyInfoService {

    @Override
    public ResultData<String> saveQualitydailyInfo(QualitydailyInfo obj) {
        boolean res = false;
        res = save(obj);
        return ResultData.ResultDataSuccess(res ? "SUCCESS" : "FAIL");
    }

    @Override
    public ResultData<String> updateQualitydailyInfo(QualitydailyInfo obj) {
        boolean res = updateById(obj);
        return ResultData.ResultDataSuccess(res ? "SUCCESS" : "FAIL");
    }

    @Override
    public ResultData<String> deleteQualitydailyInfo(QualitydailyInfo obj) {
        boolean res = removeById(obj.getIdno());
        return ResultData.ResultDataSuccess(res ? "SUCCESS" : "FAIL");
    }

    @Override
    public ResultData<QualitydailyInfo> selectPage(InfoReq req) {
        Page<QualitydailyInfo> p = new Page<>(req.getPageIndex(), req.getPageSize());
        LambdaQueryWrapper<QualitydailyInfo> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(req.getYearMonthDay()))
            wrapper.eq(QualitydailyInfo::getYearMonthDay, req.getYearMonthDay());
        if (StringUtils.isNotEmpty(req.getArea()))
            wrapper.eq(QualitydailyInfo::getArea, req.getArea());
        if (StringUtils.isNotEmpty(req.getDbegin()))
            wrapper.ge(QualitydailyInfo::getYearMonthDay, req.getDbegin());
        if (StringUtils.isNotEmpty(req.getDend()))
            wrapper.le(QualitydailyInfo::getYearMonthDay, req.getDend());

        Page<QualitydailyInfo> page = page(p, wrapper);
        List<QualitydailyInfo> list = page.getRecords();
        return ResultData.ResultDataSuccess(list, (int) page.getTotal());
    }
}
